package com.central.apps.util;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.central.app.common.feign.WorkflowClient;
import com.central.app.service.HandlerService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CloseFlowUtil {
    @Autowired
    private HandlerService handlerService;
    @Autowired
    private WorkflowClient workflowClient;
    //关闭流程接口
    public String closeFlow(String app,int id){
        String result = "流程已关闭";
        String sql = "select proc_ins_id from biz_flow_app where app = '"+app+"' and biz_id = '" + id + "'";
        List<Map<String, Object>> list = handlerService.findBySql(sql);
        if (CollectionUtils.isNotEmpty(list)) {
            String procInsId = (String) list.get(0).get("proc_ins_id");
            workflowClient.moveToEnd(procInsId);
        } else {
            result ="流程未启动，无需关闭";
        }

        return result;
    }

}
